package com.tuinui.trade.entry;

import java.math.BigDecimal;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: kaweepapkongkittisan
 * Date: 5/24/13
 * Time: 12:41 AM
 * To change this template use File | Settings | File Templates.
 */
public class PositionTodayEntry extends PositionEntry {
    protected BigDecimal change;

    protected BigDecimal percentChange;



    protected BigDecimal last;
    protected BigDecimal gainToday;
    protected BigDecimal unrealized;


    protected BigDecimal paid;
    protected BigDecimal marketValue;


    public BigDecimal getChange() {
        return change;
    }

    public void setChange(BigDecimal change) {
        this.change = change;
    }

    public BigDecimal getPercentChange() {
        return percentChange;
    }

    public void setPercentChange(BigDecimal percentChange) {
        this.percentChange = percentChange;
    }

    public BigDecimal getGainToday() {
        return gainToday;
    }

    public void setGainToday(BigDecimal gainToday) {
        this.gainToday = gainToday;
    }

    public BigDecimal getUnrealized() {
        return unrealized;
    }

    public void setUnrealized(BigDecimal unrealized) {
        this.unrealized = unrealized;
    }

    public BigDecimal getPaid() {
        return paid;
    }

    public void setPaid(BigDecimal paid) {
        this.paid = paid;
    }

    public BigDecimal getMarketValue() {
        return marketValue;
    }

    public void setMarketValue(BigDecimal marketValue) {
        this.marketValue = marketValue;
    }

    public BigDecimal getLast() {
        return last;
    }

    public void setLast(BigDecimal last) {
        this.last = last;
    }
    public static PositionTodayEntry calculatePositionToday(PositionEntry position, Map<String, StockTradeDailyEntry> priceMap){

        PositionTodayEntry todayEntry = new PositionTodayEntry();
        todayEntry.setId(position.getId());
        todayEntry.setDate(position.getDate());
        todayEntry.setOwner(position.getOwner());
        todayEntry.setPurchasedPrice(position.getPurchasedPrice());
        todayEntry.setVolume(position.getVolume());
        todayEntry.setSymbol(position.getSymbol());

        try{
            todayEntry.setChange(priceMap.get(position.getSymbol()).getChange());
            todayEntry.setGainToday(priceMap.get(position.getSymbol()).getChange().multiply(position.getVolume()));
            todayEntry.setLast(priceMap.get(position.getSymbol()).getLast());
            todayEntry.setPaid(position.getPurchasedPrice().multiply(position.getVolume()));
            todayEntry.setPercentChange(priceMap.get(position.getSymbol()).getPercentChange());
            todayEntry.setUnrealized(priceMap.get(position.getSymbol()).getLast().subtract(position.getPurchasedPrice()).multiply(position.getVolume()));
            todayEntry.setMarketValue(priceMap.get(position.getSymbol()).getLast().multiply(position.getVolume()));
        }catch(Exception e){
            e.printStackTrace();
        }

        return todayEntry;
    }

}
